package com.atguigu.classes.preconditions;

/**
 * @program: myIDEA
 * @description: 冒泡排序
 * @author: Mr.zjx
 * create: 2021-07-06-16-10
 **/
public class 冒泡排序 {
    public static void main(String[] args) {
        int[] arr = {6,2,4,9,2,4,5,6,3,2,4};
        //外循环，控制比较轮数
        for (int i = 0; i <arr.length-1;i++){
            //比较轮数每次都是递减的
            for (int j = 0;j<arr.length-i-1;j++){
            //比较换位
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        for (int i = 0;i < arr.length;i++){
            System.out.println(arr[i]);
        }
    }
}
